
<style scoped>
  .layout{
    border: 1px solid #d7dde4;
    background: #f5f7f9;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    height:100%;
    width: 100%;
  }
  .ivu-row-flex{
    height:100%;
  }
  .layout-breadcrumb{
    padding: 10px 15px 0;
  }
  .layout-content{
    min-height: 200px;
    margin: 15px;
    overflow: hidden;
    background: #fff;
    border-radius: 4px;
  }
  .layout-content-main{
    padding: 10px;
  }
  .layout-copy{
    text-align: center;
    padding: 10px 0 20px;
    color: #9ea7b4;
  }
  .layout-menu-left{
    background: #464c5b;
  }
  .layout-header{
    height: 60px;
    background: #fff;
    box-shadow: 0 1px 1px rgba(0,0,0,.1);
  }
  .layout-logo-left{
    width: 90%;
    height: 30px;
    background: #5b6270;
    border-radius: 3px;
    margin: 15px auto;
  }
  .layout-ceiling-main a{
    color: #9ba7b5;
  }
  .layout-hide-text .layout-text{
    display: none;
  }
  .ivu-col{
    transition: width .2s ease-in-out;
  }
</style>
<style>
  html,body{
    width: 100%;
    height: 100%;
    background: #f0f0f0;
    overflow: hidden;
  }
  .main{
    height: 100%;
    width: 100%;
  }
</style>
<style lang="less">
  @import "./main.less";
  @import "../styles/common.less";
</style>
<template>
  <div class="layout">
    <Row type="flex">
      <div class="main"  :class="{'main-hide-text': shrink}">
        <div class="sidebar-menu-con" :style="{width: shrink?'60px':'200px', overflow: shrink ? 'visible' : 'auto'}">
          <shrinkable-menu
            :shrink="shrink"
            @on-change="handleSubmenuChange"
            :before-push="beforePush"
            :menu-list="menuList"
          :theme="menuTheme">
            <div slot="top" class="logo-con">
              <img v-show="!shrink"  src="../images/logo.jpg" key="max-logo" />
              <img v-show="shrink" src="../images/logo-min.jpg" key="min-logo" />
            </div>
          </shrinkable-menu>
        </div>
      </div>

      <div class="main-header-con" :style="{paddingLeft: shrink?'60px':'200px'}">
        <div class="main-header">
          <div class="navicon-con">
            <Button type="text" @click="toggleClick">
              <Icon type="navicon" size="32"></Icon>
            </Button>
          </div>
          <div class="header-avator-con">

            <div class="message-con">
              <Tooltip :content="value > 0 ? '有' + value + '条未读消息' : '无未读消息'" placement="bottom">
                <Badge :count="value" dot>
                  <Icon type="ios-bell" :size="22"></Icon>
                </Badge>
              </Tooltip>
            </div>

            <div class="user-dropdown-menu-con">
              <Row type="flex" justify="end" align="middle" class="user-dropdown-innercon">
                <Dropdown transfer trigger="click" @on-click="handleClickUserDropdown">
                  <a href="javascript:void(0)">
                    <span class="main-user-name">成猛击</span>
                    <Icon type="arrow-down-b"></Icon>
                  </a>
                  <DropdownMenu slot="list">
                    <DropdownItem name="ownSpace">个人中心</DropdownItem>
                    <DropdownItem name="loginout" divided>退出登录</DropdownItem>
                  </DropdownMenu>
                </Dropdown>
                <Avatar :src="avatorPath" style="background: #619fe7;margin-left: 10px;"></Avatar>
              </Row>
            </div>
          </div>
        </div>
      </div>
      <div class="single-page-con" :style="{left: shrink?'60px':'200px'}">
      <div class="single-page">
          <router-view/>
          <div class="layout-copy">
            2011-2016 &copy; TalkingData
          </div>
        </div>
      </div>
    </Row>
  </div>
</template>
<script>
  import messageTip from '@/components/message-tip.vue';
  import shrinkableMenu from '@/components/shrinkable-menu/shrinkable-menu.vue';
  import util from '@/libs/util';
  export default {
    components: {
      shrinkableMenu,
      messageTip,
    },
    data () {
    return {
      shrink:false,
    }
  },
  computed: {
    avatorPath () {
      return localStorage.avatorImgPath;
    },
    menuList () {
      return this.$store.state.app.menuList;
    },
    avatorPath () {
      return localStorage.avatorImgPath;
    },
    value () {
      return this.$store.state.app.messageCount;
    },
    menuTheme(){
      return 'dark';
    }
  },
  methods: {
    handleSubmenuChange (val) {
      // console.log(val)
    },
    toggleClick () {
      this.shrink = !this.shrink;
    },
    changeMenu (active) {
      console.info(active);
      this.$router.push({
        name: active
      });
    },
    handleClickUserDropdown (name) {
      if (name === 'ownSpace') {
        util.openNewPage(this, 'ownspace_index');
        this.$router.push({
          name: 'ownspace_index'
        });
      } else if (name === 'loginout') {
        // 退出登录
        this.$store.commit('logout', this);
        this.$store.commit('clearOpenedSubmenu');
        this.$router.push({
          name: 'login'
        });
      }
    },
    beforePush (name) {
      if (name === 'accesstest_index') {
        return false;
      } else {
        return true;
      }
    },
  }
  }
</script>
